//
//  KRVideoPlayerViewController.m
//  YUXiu
//
//  Created by wang on 16/6/26.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "KRVideoPlayerViewController.h"

#import "KRVideoPlayerController.h"

@interface KRVideoPlayerViewController ()

@property (nonatomic, strong) KRVideoPlayerController *videoController;


@end

@implementation KRVideoPlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    float wd = self.view.frame.size.width/2;
    NSArray *arr = @[@"location",@"remote"];
    for (int i = 0; i<2; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(30 + i*(wd+30), 330,  wd - 90, 30)];
        btn.backgroundColor = [UIColor orangeColor];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickPlayer:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 10 + i;
        
        [self.view addSubview:btn];
    }

}

-(void)clickPlayer:(UIButton *)btn{
    if (btn.tag == 10) {
        //location
        NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"150511_JiveBike" withExtension:@"mov"];
        [self playVideoWithURL:videoURL];
    }else{
        //remote
        NSURL *videoURL = [NSURL URLWithString:@"http://krtv.qiniudn.com/150522nextapp"];
        //            NSURL *videoURL = [NSURL URLWithString:@"http://11945.long-vod.cdn.aodianyun.com/u/11945/m3u8/adaptive/155a4da63c32415cf7b6441d70bd77be.m3u8"];
        
        [self playVideoWithURL:videoURL];
    }
    
}

- (void)playVideoWithURL:(NSURL *)url
{
    if (!self.videoController) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        self.videoController = [[KRVideoPlayerController alloc] initWithFrame:CGRectMake(0, 20, width, width*(9.0/16.0))];
        __weak typeof(self)weakSelf = self;
        [self.videoController setDimissCompleteBlock:^{
            weakSelf.videoController = nil;
        }];
        [self.videoController showInWindow];
    }
    self.videoController.contentURL = url;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
